import 'package:flutter/material.dart';
import 'package:flutter_09_game/base/widget/base_get_builder.dart';
import 'package:flutter_09_game/config/app_color.dart';
import 'package:flutter_09_game/generated/locales.g.dart';
import 'package:flutter_09_game/pages/game/game_detail/game_detail_logic.dart';
import 'package:flutter_09_game/pages/game/game_detail/models/model_game_ws.dart';
import 'package:flutter_09_game/pages/game/game_detail/widgets/game_result_animation_widget.dart';
import 'package:flutter_09_game/pages/main/main_logic.dart';
import 'package:flutter_09_game/widgets/appbar/common_app_bar.dart';
import 'package:flutter_09_game/widgets/button/common_button.dart';
import 'package:flutter_09_game/widgets/tab/common_tab_bar_page.dart';
import 'package:flutter_09_game/widgets/tab/custom_tab_indicator.dart';
import 'package:flutter_09_game/widgets/widget_user_wallet.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class GameDetailPage extends StatelessWidget {
  GameDetailPage({super.key});

  final GameDetailLogic logic = Get.put(GameDetailLogic());

  @override
  Widget build(BuildContext context) {
    return BaseGetBuilder<GameDetailLogic>(
      backgroundColor: AppColor.navBgColor,
      appBar: CommonAppBar(
        leadingWidth: 130.w,
        title: logic.name,
        actions: [
          Obx(() {
            return WidgetUserWallet(playSound: logic.soundRx.value);
          }),
          6.horizontalSpace,
          CommonButton(
            title: LocaleKeys.recharge.tr,
            width: 48.w,
            height: 32.w,
            fontSize: 12.sp,
            horizontalPadding: 0,
            onClick: () {
              Get.back();
              Get.find<MainLogic>().changeIndex(2);
            },
          ),
          // GestureDetector(
          //   onTap: () {
          //     ModelGameWs gameWs = ModelGameWs.fromJson({
          //       "msg_type": 8,
          //       "game_id": 9,
          //       "message": {
          //         "amount": 11000000,
          //         "win_amount": 123000000,
          //         "currency": "TRX",
          //         "is_win": true,
          //         "game_id": 9,
          //         "round": 59412138
          //       }
          //     });
          //     logic.addResultToQueue(gameWs.message!);
          //     // {"msg_type":8,"game_id":9,"message":{"amount":11000000,"win_amount":0,"currency":"TRX","is_win":false,"game_id":9,"round":59412138}}
          //   },
          //   child: Container(
          //     width: 40,
          //     height: 40,
          //     color: Colors.red,
          //   ),
          // ),
          10.horizontalSpace,
        ],
      ),
      builder: (_) {
        if (logic.tabController == null) {
          return const SizedBox();
        }
        return Stack(
          children: [
            Positioned.fill(
                child: CommonTabBarPage(
              tabIsScrollable: false,
              tabBarPadding: EdgeInsets.zero,
              labelPadding: EdgeInsets.zero,
              tabController: logic.tabController!,
              indicatorSize: TabBarIndicatorSize.tab,
              indicator: CustomTabIndicator(
                width: 160.w,
                height: 2.w,
                indicatorPadding: EdgeInsets.only(top: 0.w),
                color: AppColor.primary,
                isCentered: true,
              ),
              tabData: logic.tabData,
            )),
            Positioned(
                top: 0,
                left: 0,
                right: 0,
                child: Obx(() {
                  if (logic.currentResultRx.value != null &&
                      logic.resultSlideAnimation != null &&
                      logic.resultFadeAnimation != null) {
                    return GameResultAnimationWidget(
                      result: logic.currentResultRx.value!,
                      slideAnimation: logic.resultSlideAnimation!,
                      fadeAnimation: logic.resultFadeAnimation!,
                    );
                  }
                  return const SizedBox.shrink();
                })),
          ],
        );

        // Obx(() {
        //   if (logic.currentResultRx.value != null &&
        //       logic.resultSlideAnimation != null &&
        //       logic.resultFadeAnimation != null) {
        //     return GameResultAnimationWidget(
        //       result: logic.currentResultRx.value!,
        //       slideAnimation: logic.resultSlideAnimation!,
        //       fadeAnimation: logic.resultFadeAnimation!,
        //     );
        //   }
        //   return const SizedBox.shrink();
        // })
      },
    );
    // 游戏结果动画层

    // );
  }
}
